package com.zhangwei.touch.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.zhangwei.touch
 * @Description:
 * @date 15/10/21 上午9:42
 */

public class MyView extends View {

    public OnClick onClick;


    private static final String TAG = "MyView";

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public MyView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return super.dispatchTouchEvent(event);
    }

    /**
     * 返回true 事件将向上传递 表示以消费
     * 返回 false  跟系统默认一样
     * @param event
     * @return
     *
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int downX = 0;
        int downY = 0;
        int rawX = 0;
        int rawY = 0;


        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                downX = (int) event.getX();
                downY = (int) event.getY();
                rawX = (int) event.getRawX();
                rawY = (int) event.getRawY();
                Log.e("rawX", rawX + "");
                Log.e("rawY", rawY + "");
                Log.e("downX", downX + "");
                Log.e("downY", downY + "");
                break;
            case MotionEvent.ACTION_MOVE:
                int moveX = (int) event.getX();
                int moveY = (int) event.getY();
                Log.e("moveX", moveX + "");
                Log.e("moveY", moveY + "");
                break;
            case MotionEvent.ACTION_UP:
                int upX = (int) event.getX();
                int upY = (int) event.getY();
                Log.e("upX", upX + "");
                Log.e("upY", upY + "");
                break;


        }
        return false ;
    }

    public interface OnClick {
        void onClic(View view);
    }

    public OnClick getOnClick() {
        return onClick;
    }

    public void setOnClick(OnClick onClick) {
        this.onClick = onClick;
    }
}
